package com.syedu.day05.homework;

/**
 * description：双色球摇奖
 * @author Administrator
 * @date 2022/3/11 9:38
 */
public class Exercise2 {
    public static void main(String[] args) {
        //准备球池
        int[] balls = new int[32];
        //循环赋值
        for (int i = 0; i < balls.length; i++) {
            balls[i] = i + 1;
        }
        //抽取5个小球
        for (int i = 0; i < 5; ) {
            //随机数组下标
            int index = (int) (Math.random() * 32);
            //判断随机的球是否是-1,如果是-1,说明之前抽过
            if (balls[index] == -1) {
                continue;
            }
            System.out.print(balls[index] + "\t");
            //替换该球的值
            balls[index] = -1;
            //只有当正确输出数值时,才消耗一次循环
            i++;
        }
    }
}